//
// Created by aaa on 2025/7/13.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 310;

int n,m;
int w[N],v[N];
int a[N][N],b[N],dp[N][N];

void dfs(int u){
    for(int i = w[u];i <= m;i++) dp[u][i] = v[u];

    for(int i = 0;i < b[u];i++){
        int s = a[u][i];
        dfs(s);
        for(int j = m;j >= w[u];j--){
            for(int k = 0;k <= j - w[u];k++){
                dp[u][j] = max(dp[u][j],dp[u][j-k]+dp[s][k]);
            }
        }
    }
}

// 扩展 选课 P2014
// 有依赖的背包问题
//5 6
//4 4 3
//2 2 3
//2 3 -1
//1 3 2
//1 1 2
int main(){
    int root = -1;
    cin >> n >> m;
    for(int i = 1;i <= n;i++){
        int p;
        cin >> w[i] >> v[i] >> p;
        if(p == -1) root = i;
        else a[p][b[p]++] = i;
    }

    dfs(root);

    cout << dp[root][m];

    return 0;
}